package _3_scoket项目

import (
	"fmt"
	"net"
)

func Client() {
	conn, err := net.Dial("tcp", ":8082")
	if err != nil {
		fmt.Println("net.dial err:", err)
		return
	}
	fmt.Println("client与service建立连接成功！")
	cnt, err := conn.Write([]byte("我是客户端"))
	defer conn.Close()
	if err != nil {
		fmt.Println("客户端数据写入失败...")
		return
	}
	fmt.Println("client--->service,长度:", cnt)

	//接收服务器发送的数据
	buf := make([]byte, 1024)
	cntt, err := conn.Read(buf)
	if err != nil {
		fmt.Println("数据读取失败...", err)
	}
	fmt.Println("service--->client,长度:", cntt, "数据是：", string(buf[:cntt]))
}
